Change the no_term test to run an external process.
authorMike Boutin <mike.boutin@gmail.com>
Tue, 4 Aug 2015 22:49:24 +0000 (18:49 -0400)
committerMike Boutin <mike.boutin@gmail.com>
Tue, 4 Aug 2015 23:03:00 +0000 (19:03 -0400)
Remove $TERM from the new process' environment and verify that output
is not sent to stderr.

src/cargo/core/shell.rs
tests/test_shell.rs

index 413c9aa08bad738fbd7d6c6b3ac3c51284eb7375..6e0a1956410d571e28cb5a143be010c9b1d0eb53 100644 (file)
@@ -144,6 +144,10 @@ impl MultiShell {
 
 impl Shell {
     pub fn create(out: Box<Write + Send>, config: ShellConfig) -> Shell {
+        // Match from_env() to determine if creation of a TerminfoTerminal is possible regardless
+        // of the tty status. --color options are parsed after Shell creation so always try to
+        // create a terminal that supports color output. Fall back to a no-color terminal or write
+        // output to stderr if a tty is present and color output is not possible.
         match ::term::terminfo::TermInfo::from_env() {
             Ok(ti) => {
                 // Color output is possible.
index a91e18c53f7496a758f50855dd567251f3453430..a2a5e56388bd30fc67ea5950a2bcd56187ed5e6e 100644 (file)
@@ -6,8 +6,9 @@ use hamcrest::{assert_that};
 
 use cargo::core::shell::{Shell, ShellConfig};
 use cargo::core::shell::ColorConfig::{Auto,Always, Never};
+use cargo::util::process;
 
-use support::{Tap, shell_writes};
+use support::{Tap, cargo_dir, execs, shell_writes};
 
 fn setup() {
 }
@@ -32,18 +33,6 @@ test!(non_tty {
     assert_that(&buf[..], shell_writes("Hey Alex\n"));
 });
 
-test!(no_term {
-    let config = ShellConfig { color_config: Always, tty: false };
-    let a = Arc::new(Mutex::new(Vec::new()));
-
-    ::std::env::remove_var("TERM");
-    Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
-        shell.say("Hey Alex", color::RED).unwrap();
-    });
-    let buf = a.lock().unwrap().clone();
-    assert_that(&buf[..], shell_writes("Hey Alex\n"));
-});
-
 test!(color_explicitly_disabled {
     let term = TerminfoTerminal::new(Vec::new());
     if term.is_none() { return }
@@ -90,6 +79,13 @@ test!(color_explicitly_enabled {
                                             color::RED).unwrap()));
 });
 
+test!(no_term {
+    // Verify that shell creation is successful when $TERM does not exist.
+    assert_that(process(&cargo_dir().join("cargo")).unwrap()
+                    .env_remove("TERM"),
+                execs().with_stderr(""));
+});
+
 fn colored_output(string: &str, color: color::Color) -> io::Result<String> {
     let mut term = TerminfoTerminal::new(Vec::new()).unwrap();
     try!(term.reset());